package com.znufe.exam.controller.vote;

import java.util.List;

import com.znufe.exam.base.BaseApiController;
import com.znufe.exam.viewmodel.vote.checkin.CheckInCountRequestVM;
import com.znufe.exam.viewmodel.vote.checkin.CheckInCountResponseVM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.znufe.exam.domain.CheckIn;
import com.znufe.exam.service.CheckInService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import com.znufe.exam.base.RestResponse;
import com.znufe.exam.base.SystemCode;

/**   
 * 
 * @Description:  答题器签到信息表接口层
 * @Author:       lin keqing   
 * @CreateDate:   CheckIn
 * @Version:      V1.0
 *    
 */
@Api(description = "答题器签到信息表",value="答题器签到信息表" )
@RestController
@RequestMapping("/api/checkIn")
public class CheckInController extends BaseApiController {

	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	public CheckInService checkInService;


	@RequestMapping(value="/get_class_check_in_count", method = RequestMethod.POST)
	@ApiOperation(value = "查询某个课程上某个班级的签到人数（按班级id、课程id）",
			notes = "查询某个课程上某个班级的签到人数[check_in]，作者：lin keqing")
	public RestResponse<CheckInCountResponseVM> getClassCheckInCount(@RequestBody CheckInCountRequestVM model) {
		CheckInCountResponseVM vm = checkInService.selectCheckInCount(model);
		return RestResponse.ok(vm);
	}

	/**
	 * @explain 查询答题器签到信息表对象  <swagger GET请求>
	 * @param   id
	 * @return  checkIn
	 * @author  lin keqing
	 * @time    CheckIn
	 */
	@GetMapping("/getCheckInById/{id}")
	@ApiOperation(value = "获取答题器签到信息表信息", notes = "获取答题器签到信息表信息[checkIn]，作者：lin keqing")
	@ApiImplicitParam(paramType="path", name = "id", value = "答题器签到信息表id", required = true, dataType = "Integer")
	public RestResponse<CheckIn> getCheckInById(@PathVariable("id")Integer id){

		try {
			CheckIn checkIn=checkInService.selectByPrimaryKey(id);
			if (checkIn!=null) {
				return RestResponse.ok(checkIn);
			} else {
				logger.error("查询答题器签到信息表执行失败："+checkIn.toString());
				return RestResponse.fail(SystemCode.NoDataExist.getCode(),SystemCode.NoDataExist.getMessage());
			}
		} catch (Exception e) {
			logger.error("查询答题器签到信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 添加答题器签到信息表对象
	 * @param   checkIn
	 * @return  int
	 * @author  lin keqing
	 * @time    CheckIn
	 */
	@PostMapping("/insertSelective")
	@ApiOperation(value = "添加答题器签到信息表", notes = "添加答题器签到信息表[checkIn],作者：lin keqing")
	public RestResponse<Integer> insertSelective(@RequestBody CheckIn checkIn){
		try {
			int rg=checkInService.insertSelective(checkIn);
			if (rg>0) {
				return RestResponse.ok(rg);
			} else {
				logger.error("添加答题器签到信息表执行失败："+checkIn.toString());
				return RestResponse.fail(SystemCode.InsertDataFail.getCode(),SystemCode.InsertDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("添加答题器签到信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 删除答题器签到信息表对象
	 * @param   id
	 * @return  int
	 * @author  lin keqing
	 * @time    CheckIn
	 */
	@PostMapping("/deleteByPrimaryKey")
	@ApiOperation(value = "删除答题器签到信息表", notes = "删除答题器签到信息表,作者：lin keqing")
	@ApiImplicitParam(paramType="query", name = "id", value = "答题器签到信息表id", required = true, dataType = "Integer")
	public RestResponse<Integer> deleteByPrimaryKey(Integer id){
		try {
			int reg=checkInService.deleteByPrimaryKey(id);
			if (reg>0) {
				return RestResponse.ok(reg);
			} else {
				logger.error("删除答题器签到信息表失败ID："+id);
				return RestResponse.fail(SystemCode.DeleteDataFail.getCode(),SystemCode.DeleteDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("删除答题器签到信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 修改答题器签到信息表对象
	 * @param   checkIn
	 * @return  checkIn
	 * @author  lin keqing
	 * @time    CheckIn
	 */
	@ApiOperation(value = "修改答题器签到信息表", notes = "修改答题器签到信息表[checkIn],作者：lin keqing")
	@PostMapping("/updateByPrimaryKeySelective")
	public RestResponse<Integer> updateByPrimaryKeySelective(CheckIn checkIn){
		try {
			int reg = checkInService.updateByPrimaryKeySelective(checkIn);
			if (reg>0) {
				return RestResponse.ok(reg);
			} else {
				logger.error("修改答题器签到信息表失败ID："+checkIn.toString());
				return RestResponse.fail(SystemCode.UpdateDataFail.getCode(),SystemCode.UpdateDataFail.getMessage());
			}
		} catch (Exception e) {
			logger.error("修改答题器签到信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}
	
	/**
	 * @explain 获取匹配答题器签到信息表
	 * @param   checkIn
	 * @return  List<CheckIn>
	 * @author  lin keqing
	 * @time    CheckIn
	 */
	@ApiOperation(value = "条件查询答题器签到信息表", notes = "条件查询[checkIn],作者：lin keqing")
	@PostMapping("/queryCheckInList")
	public RestResponse<List<CheckIn>> queryCheckInList(CheckIn checkIn){
		try {
			List<CheckIn> list = checkInService.queryCheckInList(checkIn);
			return RestResponse.ok(list);
		} catch (Exception e) {
			logger.error("获取答题器签到信息表执行异常："+e.getMessage());
			return RestResponse.fail(SystemCode.InnerError.getCode(),SystemCode.InnerError.getMessage());
		}
	}

}